<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Interval Arithmetic in Python &mdash; Python Interval Arithmetic v1.0 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '',
          VERSION:     '1.0',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: ''
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/interface.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="contents" title="Global table of contents" href="contents.html" />
    <link rel="index" title="Global index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Python Interval Arithmetic v1.0 documentation" href="" />
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li><a href="">Python Interval Arithmetic v1.0 documentation</a> &raquo;</li>
      </ul>
    </div>
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section">
<h1 id="interval-arithmetic-in-python">Interval Arithmetic in Python<a class="headerlink" href="#interval-arithmetic-in-python" title="Permalink to this headline">¶</a></h1>
<p>This library provides a Python implementation of an algebraically
closed interval system on the extended real number set. An interval
object consists of a finite union of closed, possibly unbound,
mathematical intervals.</p>
<div class="section">
<h2 id="installation">Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<p>The most convenient way to install this library is by means of <a class="reference" href="http://peak.telecommunity.com/DevCenter/EasyInstall">easy_install</a>:</p>
<pre>easy_install pyinterval</pre>
<p>Alternatively, it is possible to download the sources from <a class="reference" href="http://pypi.python.org/pypi/pyinterval/">PyPI</a> and invoking</p>
<pre>python setup.py install</pre>
<p>in the unpacked directory. Note that you need the <a class="reference" href="http://lipforge.ens-lyon.fr/www/crlibm/">crlibm</a> library
installed on your system. It is also possible to check-out the sources
from the subversion repository:</p>
<pre>svn checkout http://pyinterval.googlecode.com/svn/trunk/ pyinterval</pre>
</div>
<div class="section">
<h2 id="using-intervals">Using intervals<a class="headerlink" href="#using-intervals" title="Permalink to this headline">¶</a></h2>
<p>The <tt class="docutils literal"><span class="pre">interval</span></tt> package can be loaded into the Python interpreter with the statement</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">interval</span> <span class="k">import</span> <span class="n">interval</span><span class="p">,</span> <span class="n">inf</span><span class="p">,</span> <span class="n">imath</span>
</pre></div>
<p>which injects in the current namespace the interval class, a constant
representing the mathematical infinity, and a module providing
interval transcendetal functions.</p>
<p>Intervals are immutable objects that can be created by specifying their connected components:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">k</span> <span class="o">=</span> <span class="n">interval</span><span class="p">([</span><span class="mf">0</span><span class="p">,</span> <span class="mf">1</span><span class="p">],</span> <span class="p">[</span><span class="mf">2</span><span class="p">,</span> <span class="mf">3</span><span class="p">],</span> <span class="p">[</span><span class="mf">10</span><span class="p">,</span> <span class="mf">15</span><span class="p">])</span>
</pre></div>
<p>creates an object representing the union of the mathematical intervals
[0, 1], [2, 3] and [10, 15].</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span>
<span class="go">interval([1.0, 2.0])</span>
</pre></div>
<p>represents the mathematical interval [1, 2], not be confused with the
union of the one-point intervals {1} and {2}:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">(</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">)</span>
<span class="go">interval([1.0], [2.0])</span>
</pre></div>
<p>An interval consisting of only one number can be instantiated with
either forms:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">(</span><span class="mf">1</span><span class="p">),</span> <span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span>
<span class="go">(interval([1.0]), interval([1.0]))</span>
</pre></div>
<p>An empty interval has no components:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">()</span>
<span class="go">interval()</span>
</pre></div>
</div>
<div class="section">
<h2 id="operations">Operations<a class="headerlink" href="#operations" title="Permalink to this headline">¶</a></h2>
<p>Intervals can be added:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span> <span class="o">+</span> <span class="n">interval</span><span class="p">[</span><span class="mf">4</span><span class="p">,</span> <span class="mf">5</span><span class="p">]</span>
<span class="go">interval([5.0, 7.0])</span>
</pre></div>
<p>subtracted:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">5</span><span class="p">,</span> <span class="mf">7</span><span class="p">]</span> <span class="o">-</span> <span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span>
<span class="go">interval([3.0, 6.0])</span>
</pre></div>
<p>multiplied:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">0</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">interval</span><span class="p">[</span><span class="mf">4</span><span class="p">,</span> <span class="n">inf</span><span class="p">]</span>
<span class="go">interval([-inf, inf])</span>
</pre></div>
<p>divided:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span><span class="o">/</span><span class="n">interval</span><span class="p">[</span><span class="mf">3</span><span class="p">]</span>
<span class="go">interval([0.33333333333333331, 0.33333333333333337])</span>
</pre></div>
<p>inersected:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">4</span><span class="p">]</span> <span class="o">&amp;</span> <span class="n">interval</span><span class="p">[</span><span class="mf">2</span><span class="p">,</span> <span class="mf">5</span><span class="p">]</span>
<span class="go">interval([2.0, 4.0])</span>
</pre></div>
<p>unioned:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">4</span><span class="p">]</span> <span class="o">|</span> <span class="n">interval</span><span class="p">[</span><span class="mf">2</span><span class="p">,</span> <span class="mf">5</span><span class="p">]</span>
<span class="go">interval([1.0, 5.0])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span> <span class="o">|</span> <span class="n">interval</span><span class="p">[</span><span class="mf">4</span><span class="p">,</span> <span class="mf">5</span><span class="p">]</span>
<span class="go">interval([1.0, 2.0], [4.0, 5.0])</span>
</pre></div>
<p>raised to integer power:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="o">-</span><span class="mf">3</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span> <span class="o">**</span> <span class="mf">2</span>
<span class="go">interval([0.0, 9.0])</span>
</pre></div>
<p>Scalar numbers are automatically cast as interval when used as
operands together with intervals:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="mf">1</span><span class="o">/</span><span class="n">interval</span><span class="p">[</span><span class="mf">3</span><span class="p">]</span> <span class="o">==</span> <span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span><span class="o">/</span><span class="n">interval</span><span class="p">[</span><span class="mf">3</span><span class="p">]</span>
<span class="go">True</span>
</pre></div>
<p>The <a class="reference" href="#module-interval.imath">imath</a> module provides transcendental
functions that accept interval arguments. For instance,</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">imath</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">interval</span><span class="p">[</span><span class="mf">0</span><span class="p">,</span> <span class="mf">1</span><span class="p">])</span>
<span class="go">interval([1.0, 2.7182818284590455])</span>
</pre></div>
</div>
<div class="section">
<h2 id="inspection">Inspection<a class="headerlink" href="#inspection" title="Permalink to this headline">¶</a></h2>
<p>The <tt class="docutils literal"><span class="pre">in</span></tt> operator can be used to test whether a scalar is in a interval:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="mf">0</span> <span class="ow">in</span> <span class="n">interval</span><span class="p">[</span><span class="o">-</span><span class="mf">1</span><span class="p">,</span> <span class="mf">1</span><span class="p">]</span>
<span class="go">True</span>

<span class="gp">&gt;&gt;&gt; </span><span class="mf">0</span> <span class="ow">in</span> <span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span>
<span class="go">False</span>
</pre></div>
<p>or whether an interval is a subset of another interval:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span> <span class="ow">in</span> <span class="n">interval</span><span class="p">[</span><span class="mf">0</span><span class="p">,</span> <span class="mf">3</span><span class="p">]</span>
<span class="go">True</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span> <span class="ow">in</span> <span class="n">interval</span><span class="p">[</span><span class="mf">1.5</span><span class="p">,</span> <span class="mf">3</span><span class="p">]</span>
<span class="go">False</span>
</pre></div>
<p>The <tt class="docutils literal"><span class="pre">len</span></tt> operator returns the number of connected components in the
interval:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">interval</span><span class="p">())</span>
<span class="go">0</span>

<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">])</span>
<span class="go">1</span>

<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">interval</span><span class="p">(</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">))</span>
<span class="go">2</span>
</pre></div>
<p>It is possible to iterate on an interval components as in the
statement</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">interval</span><span class="p">([</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">],</span> <span class="mf">3</span><span class="p">)</span><span class="o">.</span><span class="n">components</span><span class="p">]</span>
<span class="go">[interval([1.0, 2.0]), interval([3.0])]</span>
</pre></div>
<p>The endpoints are given by</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">([</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">],</span> <span class="mf">3</span><span class="p">)</span><span class="o">.</span><span class="n">extrema</span>
<span class="go">interval([1.0], [2.0], [3.0])</span>
</pre></div>
<p>and the midpoints by</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">([</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">],</span> <span class="mf">3</span><span class="p">)</span><span class="o">.</span><span class="n">midpoint</span>
<span class="go">interval([1.5], [3.0])</span>
</pre></div>
</div>
</div>
<div class="section">
<h1 id="modules">Modules<a class="headerlink" href="#modules" title="Permalink to this headline">¶</a></h1>
<p>The code is organized in three modules:</p>
<blockquote>
<ul class="simple">
<li><a class="reference" href="#module-interval">interval</a>, providing the interval class;</li>
<li><a class="reference" href="#module-interval.fpu">interval.fpu</a>, providing lower-level control and helper functions;</li>
<li><a class="reference" href="#module-interval.imath">interval.imath</a>, imath, providing transendental functions for interval, akin to math for floats.</li>
</ul>
</blockquote>
<div class="section">
<h2 id="module-interval">interval<a class="headerlink" href="#module-interval" title="Permalink to this headline">¶</a></h2>
<dl class="docutils">
<dt><strong>interval</strong></dt>
<dd>An algebraically closed interval system on the extended real set.</dd>
</dl>
<p>This package provides the interval class, which is usually imported
into the current namespace:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">interval</span> <span class="k">import</span> <span class="n">interval</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span><span class="mf">2</span><span class="p">]</span>
<span class="go">interval([1.0, 2.0])</span>
</pre></div>
<dl class="data">
<dt id="interval.inf">
<!--[interval.inf]--><tt class="descclassname">interval.</tt><tt class="descname">inf</tt><a class="headerlink" href="#interval.inf" title="Permalink to this definition">¶</a></dt>
<dd><p>Infinity in the sense of IEEE 754. Identical to <a title="interval.fpu.infinity" class="reference" href="#interval.fpu.infinity"><tt class="xref docutils literal"><span class="pre">interval.fpu.infinity</span></tt></a>.</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">inf</span> <span class="o">+</span> <span class="n">inf</span> <span class="o">==</span> <span class="n">inf</span>
<span class="go">True</span>
</pre></div>
</dd></dl>

<dl class="class">
<dt id="interval.interval">
<!--[interval.interval]-->class <tt class="descclassname">interval.</tt><tt class="descname">interval</tt><a class="headerlink" href="#interval.interval" title="Permalink to this definition">¶</a></dt>
<dd><p>A (multi-)interval on the extended real set.</p>
<p>An interval is an immutable object that is created by specifying
the end-points of its connected components:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">([</span><span class="mf">0</span><span class="p">,</span> <span class="mf">1</span><span class="p">],</span> <span class="p">[</span><span class="mf">2</span><span class="p">,</span> <span class="mf">3</span><span class="p">],</span> <span class="p">[</span><span class="mf">10</span><span class="p">,</span> <span class="mf">15</span><span class="p">])</span>
<span class="go">interval([0.0, 1.0], [2.0, 3.0], [10.0, 15.0])</span>
</pre></div>
<p>constructs an interval whose arbitrary element x must satisfy 0 &lt;=
x &lt;= 1 or 2 &lt;= x &lt;= 3 or 10 &lt;= x &lt;= 15. Several shortcuts are
available:</p>
<blockquote>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">(</span><span class="mf">1</span><span class="p">,</span> <span class="p">[</span><span class="mf">2</span><span class="p">,</span> <span class="mf">3</span><span class="p">])</span>
<span class="go">interval([1.0], [2.0, 3.0])</span>
</pre></div>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">]</span>
<span class="go">interval([1.0, 2.0])</span>
</pre></div>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span>
<span class="go">interval([1.0])</span>
</pre></div>
</blockquote>
<p>Intervals are closed with respect to all arithmetic operations,
integer power, union, and intersection. Casting is provided for
scalars in the real set.</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mf">1</span> <span class="o">+</span> <span class="n">interval</span><span class="p">[</span><span class="mf">3</span><span class="p">,</span> <span class="mf">4</span><span class="p">]</span> <span class="o">/</span> <span class="n">interval</span><span class="p">[</span><span class="o">-</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">])</span> <span class="o">&amp;</span> <span class="n">interval</span><span class="p">[</span><span class="o">-</span><span class="mf">5</span><span class="p">,</span> <span class="mf">5</span><span class="p">]</span>
<span class="go">interval([-5.0, -2.0], [2.5, 5.0])</span>
</pre></div>
<dl class="attribute">
<dt id="interval.interval.cast">
<!--[interval.interval.cast]--><tt class="descname">cast</tt><a class="headerlink" href="#interval.interval.cast" title="Permalink to this definition">¶</a></dt>
<dd><p>Cast a scalar to an interval.</p>
<p>If the argument is an interval, it is returned unchanged. If
the argument is not a scalar an interval.ScalarError is
raised:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="s">&#39;asd&#39;</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">ScalarError: Invalid scalar: &#39;asd&#39;</span>
</pre></div>
</dd></dl>

<dl class="method">
<dt id="interval.interval.format">
<!--[interval.interval.format]--><tt class="descname">format</tt><big>(</big><em>fs</em><big>)</big><a class="headerlink" href="#interval.interval.format" title="Permalink to this definition">¶</a></dt>
<dd><p>Format into a string using fs as format for the interval bounds.</p>
<p>The argument fs can be any string format valid with floats:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="o">-</span><span class="mf">2.1</span><span class="p">,</span> <span class="mf">3.4</span><span class="p">]</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%+g</span><span class="s">&quot;</span><span class="p">)</span>
<span class="go">&#39;interval([-2.1, +3.4])&#39;</span>
</pre></div>
</dd></dl>

<dl class="attribute">
<dt id="interval.interval.function">
<!--[interval.interval.function]--><tt class="descname">function</tt><a class="headerlink" href="#interval.interval.function" title="Permalink to this definition">¶</a></dt>
<dd><p>Decorator creating an interval function from a function on a single component.</p>
<p>The original function accepts one argument and returns a sequence
of (inf, sup) pairs:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="nd">@interval</span><span class="o">.</span><span class="n">function</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">mirror</span><span class="p">(</span><span class="n">c</span><span class="p">):</span>
<span class="gp">... </span>   <span class="k">return</span> <span class="p">(</span><span class="o">-</span><span class="n">c</span><span class="o">.</span><span class="n">sup</span><span class="p">,</span> <span class="o">-</span><span class="n">c</span><span class="o">.</span><span class="n">inf</span><span class="p">),</span> <span class="n">c</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mirror</span><span class="p">(</span><span class="n">interval</span><span class="p">([</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">],</span> <span class="mf">3</span><span class="p">))</span>
<span class="go">interval([-3.0], [-2.0, -1.0], [1.0, 2.0], [3.0])</span>
</pre></div>
</dd></dl>

<dl class="attribute">
<dt id="interval.interval.hull">
<!--[interval.interval.hull]--><tt class="descname">hull</tt><a class="headerlink" href="#interval.interval.hull" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the hull of the specified intervals.</p>
<p>The hull of a set of intervals is the smallest connected
interval enclosing all the intervals.</p>
<blockquote>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="o">.</span><span class="n">hull</span><span class="p">((</span><span class="n">interval</span><span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">3</span><span class="p">],</span> <span class="n">interval</span><span class="p">[</span><span class="mf">10</span><span class="p">,</span> <span class="mf">15</span><span class="p">]))</span>
<span class="go">interval([1.0, 15.0])</span>
</pre></div>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="o">.</span><span class="n">hull</span><span class="p">([</span><span class="n">interval</span><span class="p">(</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">)])</span>
<span class="go">interval([1.0, 2.0])</span>
</pre></div>
</blockquote>
</dd></dl>

<dl class="method">
<dt id="interval.interval.inverse">
<!--[interval.interval.inverse]--><tt class="descname">inverse</tt><big>(</big><em>x</em><big>)</big><a class="headerlink" href="#interval.interval.inverse" title="Permalink to this definition">¶</a></dt>
<dd>Return self ** -1, or, equivalently, 1 / self.</dd></dl>

<dl class="attribute">
<dt id="interval.interval.new">
<!--[interval.interval.new]--><tt class="descname">new</tt><a class="headerlink" href="#interval.interval.new" title="Permalink to this definition">¶</a></dt>
<dd>Create a new interval from existing components.</dd></dl>

<dl class="method">
<dt id="interval.interval.newton">
<!--[interval.interval.newton]--><tt class="descname">newton</tt><big>(</big><em>f</em>, <em>p</em>, <em>maxiter=10000</em>, <em>tracer_cb=None</em><big>)</big><a class="headerlink" href="#interval.interval.newton" title="Permalink to this definition">¶</a></dt>
<dd><p>Find the roots of f(x) (where p=df/dx) within self using Newton-Raphson.</p>
<p>For instance, the following solves x**3 == x in [-10, 10]:</p>
<blockquote>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="o">-</span><span class="mf">10</span><span class="p">,</span> <span class="mf">10</span><span class="p">]</span><span class="o">.</span><span class="n">newton</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">-</span> <span class="n">x</span><span class="o">**</span><span class="mf">3</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> <span class="o">-</span> <span class="mf">3</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mf">2</span><span class="p">)</span>
<span class="go">interval([-1.0], [0.0], [1.0])</span>
</pre></div>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">[</span><span class="o">-</span><span class="mf">1.5</span><span class="p">,</span> <span class="mf">3</span><span class="p">]</span><span class="o">.</span><span class="n">newton</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mf">2</span> <span class="o">-</span> <span class="mf">1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mf">2</span><span class="p">),</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span><span class="mf">3</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mf">2</span> <span class="o">-</span> <span class="mf">4</span><span class="o">*</span><span class="n">x</span> <span class="o">-</span><span class="mf">1</span><span class="p">)</span>
<span class="go">interval([-1.0], [1.0], [2.0])</span>
</pre></div>
</blockquote>
</dd></dl>

<dl class="attribute">
<dt id="interval.interval.union">
<!--[interval.interval.union]--><tt class="descname">union</tt><a class="headerlink" href="#interval.interval.union" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the union of the specified intervals.</p>
<p>This class method is equivalent to the repeated use of the | operator.</p>
<blockquote>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="o">.</span><span class="n">union</span><span class="p">([</span><span class="n">interval</span><span class="p">([</span><span class="mf">1</span><span class="p">,</span> <span class="mf">3</span><span class="p">],</span> <span class="p">[</span><span class="mf">4</span><span class="p">,</span> <span class="mf">6</span><span class="p">]),</span> <span class="n">interval</span><span class="p">([</span><span class="mf">2</span><span class="p">,</span> <span class="mf">5</span><span class="p">],</span> <span class="mf">9</span><span class="p">)])</span>
<span class="go">interval([1.0, 6.0], [9.0])</span>
</pre></div>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interval</span><span class="p">([</span><span class="mf">1</span><span class="p">,</span> <span class="mf">3</span><span class="p">],</span> <span class="p">[</span><span class="mf">4</span><span class="p">,</span> <span class="mf">6</span><span class="p">])</span> <span class="o">|</span> <span class="n">interval</span><span class="p">([</span><span class="mf">2</span><span class="p">,</span> <span class="mf">5</span><span class="p">],</span> <span class="mf">9</span><span class="p">)</span>
<span class="go">interval([1.0, 6.0], [9.0])</span>
</pre></div>
</blockquote>
</dd></dl>

</dd></dl>

</div>
<div class="section">
<h2 id="module-interval.fpu">interval.fpu<a class="headerlink" href="#module-interval.fpu" title="Permalink to this headline">¶</a></h2>
<dl class="docutils">
<dt><strong>interval.fpu</strong></dt>
<dd>Floating-point unit control and helper functions.</dd>
</dl>
<p>This module provides:</p>
<blockquote>
<ol class="arabic simple">
<li>Mechanisms for the control of the FPU&#8217;s rounding modes;</li>
<li>Helper functions that respect IEEE 754 semantics.</li>
</ol>
</blockquote>
<dl class="docutils">
<dt>Limitations</dt>
<dd>The current implementation of the FPU&#8217;s rounding-mode control is
thought to be not thread-safe.</dd>
</dl>
<dl class="data">
<dt id="interval.fpu.infinity">
<!--[interval.fpu.infinity]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">infinity</tt><a class="headerlink" href="#interval.fpu.infinity" title="Permalink to this definition">¶</a></dt>
<dd><p>Infinity in the sense of IEEE 754. Also exported  as <a title="interval.inf" class="reference" href="#interval.inf"><tt class="xref docutils literal"><span class="pre">interval.inf</span></tt></a>.</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">interval</span> <span class="k">import</span> <span class="n">fpu</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fpu</span><span class="o">.</span><span class="n">infinity</span> <span class="o">+</span> <span class="n">fpu</span><span class="o">.</span><span class="n">infinity</span> <span class="o">==</span> <span class="n">fpu</span><span class="o">.</span><span class="n">infinity</span>
<span class="go">True</span>
</pre></div>
</dd></dl>

<dl class="data">
<dt id="interval.fpu.nan">
<!--[interval.fpu.nan]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">nan</tt><a class="headerlink" href="#interval.fpu.nan" title="Permalink to this definition">¶</a></dt>
<dd><p>An instance of not-a-number, also in the sense of IEEE 754. Note
that you cannot use nan in conditional clauses. Use isnan
instead.</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">interval</span> <span class="k">import</span> <span class="n">fpu</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fpu</span><span class="o">.</span><span class="n">nan</span> <span class="o">==</span> <span class="n">fpu</span><span class="o">.</span><span class="n">nan</span>
<span class="go">False</span>
</pre></div>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">fpu</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">fpu</span><span class="o">.</span><span class="n">nan</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</dd></dl>

<dl class="exception">
<dt id="interval.fpu.NanException">
<!--[interval.fpu.NanException]-->exception <tt class="descclassname">interval.fpu.</tt><tt class="descname">NanException</tt><a class="headerlink" href="#interval.fpu.NanException" title="Permalink to this definition">¶</a></dt>
<dd>Exception thrown when an unwanted nan is encountered.</dd></dl>

<dl class="function">
<dt id="interval.fpu.down">
<!--[interval.fpu.down]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">down</tt><big>(</big><em>f</em><big>)</big><a class="headerlink" href="#interval.fpu.down" title="Permalink to this definition">¶</a></dt>
<dd>Perform a computation with the FPU rounding downwards.</dd></dl>

<dl class="function">
<dt id="interval.fpu.ensure_nonan">
<!--[interval.fpu.ensure_nonan]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">ensure_nonan</tt><big>(</big><em>x</em><big>)</big><a class="headerlink" href="#interval.fpu.ensure_nonan" title="Permalink to this definition">¶</a></dt>
<dd>Return x, throwing a NanException if x is nan.</dd></dl>

<dl class="function">
<dt id="interval.fpu.isnan">
<!--[interval.fpu.isnan]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">isnan</tt><big>(</big><em>x</em><big>)</big><a class="headerlink" href="#interval.fpu.isnan" title="Permalink to this definition">¶</a></dt>
<dd>Return True if x is nan.</dd></dl>

<dl class="function">
<dt id="interval.fpu.max">
<!--[interval.fpu.max]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">max</tt><big>(</big><em>l</em><big>)</big><a class="headerlink" href="#interval.fpu.max" title="Permalink to this definition">¶</a></dt>
<dd>Return the maximum of the elements in l, or nan if any element is nan.</dd></dl>

<dl class="function">
<dt id="interval.fpu.min">
<!--[interval.fpu.min]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">min</tt><big>(</big><em>l</em><big>)</big><a class="headerlink" href="#interval.fpu.min" title="Permalink to this definition">¶</a></dt>
<dd>Return the minimum of the elements in l, or nan if any element is nan.</dd></dl>

<dl class="function">
<dt id="interval.fpu.power_rd">
<!--[interval.fpu.power_rd]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">power_rd</tt><big>(</big><em>x</em>, <em>n</em><big>)</big><a class="headerlink" href="#interval.fpu.power_rd" title="Permalink to this definition">¶</a></dt>
<dd>Raise x to the n-th power (with n positive integer), rounded toward -inf.</dd></dl>

<dl class="function">
<dt id="interval.fpu.power_rn">
<!--[interval.fpu.power_rn]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">power_rn</tt><big>(</big><em>x</em>, <em>n</em><big>)</big><a class="headerlink" href="#interval.fpu.power_rn" title="Permalink to this definition">¶</a></dt>
<dd>Raise x to the n-th power (with n positive integer), rounded to nearest.</dd></dl>

<dl class="function">
<dt id="interval.fpu.power_ru">
<!--[interval.fpu.power_ru]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">power_ru</tt><big>(</big><em>x</em>, <em>n</em><big>)</big><a class="headerlink" href="#interval.fpu.power_ru" title="Permalink to this definition">¶</a></dt>
<dd>Raise x to the n-th power (with n positive integer), rounded toward +inf.</dd></dl>

<dl class="function">
<dt id="interval.fpu.up">
<!--[interval.fpu.up]--><tt class="descclassname">interval.fpu.</tt><tt class="descname">up</tt><big>(</big><em>f</em><big>)</big><a class="headerlink" href="#interval.fpu.up" title="Permalink to this definition">¶</a></dt>
<dd>Perform a computation with the FPU rounding upwards.</dd></dl>

</div>
<div class="section">
<h2 id="module-interval.imath">interval.imath<a class="headerlink" href="#module-interval.imath" title="Permalink to this headline">¶</a></h2>
<dl class="docutils">
<dt><strong>interval.imath</strong></dt>
<dd>Mathematical function library for intervals.</dd>
</dl>
<p>This module provides transcendental functions with interval argument.</p>
</div>
</div>
<div class="section">
<h1 id="indices-and-tables">Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
<ul class="simple">
<li><a class="reference" href="genindex.html"><em>Index</em></a></li>
<li><a class="reference" href="search.html"><em>Search Page</em></a></li>
</ul>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3>Table Of Contents</h3>
            <ul>
<li><a class="reference" href="">Interval Arithmetic in Python</a><ul>
<li><a class="reference" href="#installation">Installation</a></li>
<li><a class="reference" href="#using-intervals">Using intervals</a></li>
<li><a class="reference" href="#operations">Operations</a></li>
<li><a class="reference" href="#inspection">Inspection</a></li>
</ul>
</li>
<li><a class="reference" href="#modules">Modules</a><ul>
<li><a class="reference" href="#module-interval">interval</a></li>
<li><a class="reference" href="#module-interval.fpu">interval.fpu</a></li>
<li><a class="reference" href="#module-interval.imath">interval.imath</a></li>
</ul>
</li>
<li><a class="reference" href="#indices-and-tables">Indices and tables</a></li>
</ul>

            <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li><a href="">Python Interval Arithmetic v1.0 documentation</a> &raquo;</li>
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Stefano Taschini.
      Last updated on Aug 27, 2008.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
    </div>
  </body>
</html>